package com.c2soft.ncmxBtrade.webApp;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

public class WebApp extends
		AbstractAnnotationConfigDispatcherServletInitializer {
	@Override
	protected Class<?>[] getRootConfigClasses() {
		return new Class<?>[0];
	}

	@Override
	protected Class<?>[] getServletConfigClasses() {
		return new Class<?>[] { WebAppConfig.class };
	}

	@Override
	protected String[] getServletMappings() {
		return new String[] { "/" };
	}

	@Configuration
	@EnableWebMvc
	@Import({JavaConfig.class,WebSocketConfig.class})
	@ComponentScan({"com.c2soft.ncmxBtrade.controller","com.c2soft.ncmxBtrade.controller.page","com.c2soft.ncmxBtrade.command" })
	public static class WebAppConfig extends WebMvcConfigurerAdapter {
	
		@Override
		public void addResourceHandlers(ResourceHandlerRegistry registry) {
			registry.addResourceHandler("/assets/css/**")
					.addResourceLocations("classpath:/assets/css/")
					.setCachePeriod(31556926);
			registry.addResourceHandler("/assets/img/**")
			        .addResourceLocations("classpath:/assets/img/")
			        .setCachePeriod(31556926);
			registry.addResourceHandler("/css/css/**")
	                .addResourceLocations("classpath:/css/css/")
	                .setCachePeriod(31556926);
			registry.addResourceHandler("/css/**")
					.addResourceLocations("classpath:/css/")
					.setCachePeriod(31556926);
			registry.addResourceHandler("/images/**")
					.addResourceLocations("classpath:/images/")
					.setCachePeriod(31556926);
			registry.addResourceHandler("/img/**")
			        .addResourceLocations("classpath:/img/")
			        .setCachePeriod(31556926);
			registry.addResourceHandler("/js/**")
					.addResourceLocations("classpath:/js/")
					.setCachePeriod(31556926);
			registry.addResourceHandler("/css/websymbols/**")
					.addResourceLocations("classpath:/css/websymbols/")
					.setCachePeriod(31556926);
			registry.addResourceHandler("/font/**")
					.addResourceLocations("classpath:/font/")
					.setCachePeriod(31556926);
			registry.addResourceHandler("/css/websymbols/specimen_files/**")
			        .addResourceLocations("classpath:/css/websymbols/specimen_files/")
			        .setCachePeriod(31556926);
			registry.addResourceHandler("/arcadiacharts/loader/**")
	                .addResourceLocations("classpath:/arcadiacharts/loader/")
	                .setCachePeriod(31556926);
			registry.addResourceHandler("/resources/img/**")
                    .addResourceLocations("classpath:/resources/img/")
                    .setCachePeriod(31556926);
			registry.addResourceHandler("/data/**")
                    .addResourceLocations("classpath:/data/")
                    .setCachePeriod(31556926);
			registry.addResourceHandler("/js/assets/bootstrap/js/**")
                    .addResourceLocations("classpath:/js/assets/bootstrap/js/")
                    .setCachePeriod(31556926);
			registry.addResourceHandler("/js/assets/jquery/**")
                    .addResourceLocations("classpath:/js/assets/jquery/")
                    .setCachePeriod(31556926);
			registry.addResourceHandler("/js/assets/number-updown/js/**")
                    .addResourceLocations("classpath:/js/assets/number-updown/js/")
                    .setCachePeriod(31556926);
			registry.addResourceHandler("/js/assets/prettify/**")
                    .addResourceLocations("classpath:/js/assets/prettify/")
                    .setCachePeriod(31556926);
			registry.addResourceHandler("/assets/chart/**")
    		.addResourceLocations("classpath:/assets/chart/")
    		.setCachePeriod(31556926);
		}
		
		@Bean
	    public InternalResourceViewResolver getInternalResourceViewResolver() {
	        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
	        resolver.setPrefix("/WEB-INF/pages/");
	        resolver.setSuffix(".jsp");
	        return resolver;
	    }
	}
}
